require(['config'],()=>{
    require(['pAjax'],()=>{
    class Details{
        constructor(){
            this.details = document.querySelector('.details')
            this.pic = document.querySelector('.pic>img')                             
            // this.pic1 = document.querySelector('.picRight>img')          
            this.long_title = document.querySelector('.long_title')
            this.span = document.querySelector('.r_second>span')            
            this.init()
        }
        init(){
            this.request()
                       
            
        }
        getQueryStr(name){
            let str = location.search.slice(1)
            // console.log(str);
            let arr = str.split('=')
            let obj ={}
            obj[arr[0]] = arr[1]
            return obj[name]
        }
        request(){
            let id = this.getQueryStr('id') - 0
            if(!id){
                location.href = '/index.html'
                return false
            }else{
                pAjax({url:'/api/goods.json'})
                .then( data =>{
                let res = JSON.parse(data)
                // console.log(data);
                res = res.slice(0, 24)
                console.log(res);
                let goods = res.find(item=>{return item.goods_id == id})
                this.render(goods)
            })
            }
        }
        render(data){
            this.pic.src= data.img_small_logo
            // this.pic1.src= data.img_big_logo
            this.span.innerHTML= data.price
            this.long_title.innerHTML = data.title
            this.details.innerHTML = data.goods_introduce   
           
        }
        
        
}
    new Details()
})
})